#ifndef QNINEPATCH_H
#define QNINEPATCH_H
#include <QPicture>
#include <QPixmap>
#include <QRect>
#include <QString>
#include <QSize>
#include <QByteArray>
#include <QList>
#include <QFileInfo>
#include <QImage>
#include <QRgb>
#include <QDebug>
#include <QByteArray>
#include <QPoint>
#include <QPainter>

class QNinePatchItem {
public:
    enum MATCH_Align {
        None        = 0x0000,
        Top         = 0x0001,
        Left        = 0x0002,
        Right       = 0x0004,
        Bottom      = 0x0008,
        Center      = 0x000A,
        TopLeft     = Top|Left,
        TopRight    = Top|Right,
        BottomLeft  = Bottom|Left,
        BottomRight = Bottom|Right
    };

    enum ChunkType {
        ChunkHorizontal = 0x0001,
        ChunkVertical   = 0x0002,
        ChunkBoth       = ChunkHorizontal|ChunkVertical
    };

    bool isChunk;
    MATCH_Align mMatch;
    ChunkType mType;
    QRect mRect;
};

class QNinePatch
{
public:
    QNinePatch(QString);
    ~QNinePatch();
    QImage getNinePatchPicture(QSize);
    void noneChunkPaint(QPainter*, QSize size);
    void chunkPaint(QPainter*, QSize size);
    QPixmap getOrgPicture(QSize size){
        return mOrgData->copy(0, 0, size.width(), size.height());
    }

    QList<QNinePatchItem*> getResizePatch();
    bool isNinePatch;

private:
    QList<QRect> mNoneChunkRect;
    QList<QRect> mChunkRect;
    QList<QNinePatchItem*> mPatchList;
    QPixmap* mOrgData;
};

#endif // QNINEPATCH_H
